#define _CRT_SECURE_NO_WARNINGS   1

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 1010;

int f[N]; 
int v[N], w[N]; 

int main()
{
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++) cin >> v[i] >> w[i];
	memset(f, -0x3f, sizeof f);   
	f[0] = 0; 
	for (int i = 1; i <= n; i++)
	for (int j = m; j >= v[i]; j--) 
	{
		f[j] = max(f[j], f[j - v[i]] + w[i]); 
	}

	int ans1 = 0, ans2 = 0;
	for (int i = 0; i <= m; i++) ans1 = max(ans1, f[i]); 

	if (f[m] < 0) ans2 = 0;
	else ans2 = f[m];  

	cout << ans1 << endl;
	cout << ans2 << endl;
}
